package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC479 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int largestPalindrome(int n) {
            if (n == 1) {
                return 9;
            }
            int upper = (int) Math.pow(10, n) - 1;
            int ans = 0;
            for (int left = upper; ans == 0; --left) { // 枚举回文数的左半部分
                long p = left;
                for (int x = left; x > 0; x /= 10) {
                    p = p * 10 + x % 10; // 翻转左半部分到其自身末尾，构造回文数 p
                }
                for (long x = upper; x * x >= p; --x) {
                    if (p % x == 0) { // x 是 p 的因子
                        ans = (int) (p % 1337);
                        break;
                    }
                }
            }
            return ans;
        }
    }


    public void run() {
        int[] arr = InputUtil.toIntegerArray("[1,2,3]");
        System.out.println(new Solution().toString());
    }

    public static void main(String[] args) throws Exception {
        LC479 an = new LC479();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
